import React from 'react'
import {Form,Card,Button,Input,message} from 'antd';

function Edit(props) {
    const { getFieldDecorator } = props.form;
    const handleSubmit = e =>{
        e.preventDefault()
        props.form.validateFieldsAndScroll((err,values) => {
            if(!err){
                console.log("提交");
                console.log(values.source_word_txt);
                let url = 'https://www.304cloud.top:4321/addsource_word';
                let txt = values.source_word_txt;
                fetch(url,{
                    method:'POST',
                    headers:{
                        'Content-Type' : 'multipart/form-data'
                    },
                    body:JSON.stringify({'source_word_txt':txt})
                })
                .then(res=>{
                    console.log(res)
                    props.history.push('/admin/txt')
                })

            }else{
                message.error('请输入正确的内容')
            }
        })
    }
    return (
        <Card title="素材编辑">
            <Form onSubmit={e=>handleSubmit(e)}>
                <Form.Item label="文字素材">{
                    getFieldDecorator('source_word_txt',{
                        rules:[
                            {
                                required:true,
                                message:'请输入文字素材'
                            }
                        ]
                    })(<Input placehoder="请输入文字素材内容"/>)
                }     
                </Form.Item>
                <Form.Item>
                    <Button htmlType="submit" type="primary">上传</Button>
                </Form.Item>
            </Form>
        </Card>
    )
}

export default Form.create({name :'txtEdit'})(Edit);
